<?php
namespace app\base\controller;

use app\base\model\BanjiModel;
use app\common\base\BasicRest;
use think\Request;
use think\Session;

class Banji extends  BasicRest
{
    public function __construct()
    {
        parent::__construct();
    }

    #获取班级信息
    public function index(){
        $banjidata = BanjiModel::where('IsDeleted',0)->where('kind',2)->select();
        $nianjidata = BanjiModel::where('IsDeleted',0)->where('kind',1)->select();
        return res_success(['nianjidata'=>$nianjidata,'banjidata'=>$banjidata]);
    }

    #获取单个班级信息
    public function read($id){
        $banjidata = BanjiModel::get($id);
        if($banjidata) return res_success($subjectData);
        return res_fail('未找到信息');
    }

    #新增班级信息
    public function save(Request $request){
        $res = BanjiModel::create(['Title'=>$request->post('Title'),'Kind'=>$request->post('Kind')]);
        if($res) return res_success();
        return res_fail('创建失败');
    }

    #修改班级信息
    public function update(Request $request,$id){
        $model = BanjiModel::find($id);
        $res = $model->save(['Title'=>$request->put('Title')]);
        if($res!== false) return res_success();
        return res_fail('修改失败');
    }

    #删除班级信息
    public function delete($id){
        $res = BanjiModel::where('Id',$id)->update(['IsDeleted'=>'1']);
        if($res) return res_success();
        return res_fail('删除失败');
    }
}